﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_v5_ettevotja", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedV5Ettevotja))]
    public class DetailandmedV5EttevotjaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedV5Ettevotja clazz;
        
        public DetailandmedV5EttevotjaSerializer(IDetailandmedV5Ettevotja clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.AriregistriKood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ettevotja_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.EttevotjaId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("nimi");
            if (clazz.Nimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimi");
            }
            Writer.WriteEndElement();
            if (clazz.Yldandmed!=null) {
                Writer.WriteStartElement("yldandmed");
                global::Xtee.Core.SerializationMetadata metaYldandmed = this.GetMetaData(clazz.Yldandmed);
                Writer.WriteTypeAttribute(metaYldandmed.TypeQualifiedName.Namespace, metaYldandmed.TypeQualifiedName.Name);
                metaYldandmed.NewSerializer(clazz.Yldandmed).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Isikuandmed!=null) {
                Writer.WriteStartElement("isikuandmed");
                global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData(clazz.Isikuandmed);
                Writer.WriteTypeAttribute(metaIsikuandmed.TypeQualifiedName.Namespace, metaIsikuandmed.TypeQualifiedName.Name);
                metaIsikuandmed.NewSerializer(clazz.Isikuandmed).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Kommertspandiandmed!=null) {
                Writer.WriteStartElement("kommertspandiandmed");
                global::Xtee.Core.SerializationMetadata metaKommertspandiandmed = this.GetMetaData(clazz.Kommertspandiandmed);
                Writer.WriteTypeAttribute(metaKommertspandiandmed.TypeQualifiedName.Namespace, metaKommertspandiandmed.TypeQualifiedName.Name);
                metaKommertspandiandmed.NewSerializer(clazz.Kommertspandiandmed).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.MenetlusesAvaldused!=null) {
                Writer.WriteStartElement("menetluses_avaldused");
                global::Xtee.Core.SerializationMetadata metaMenetlusesAvaldused = this.GetMetaData(clazz.MenetlusesAvaldused);
                Writer.WriteTypeAttribute(metaMenetlusesAvaldused.TypeQualifiedName.Namespace, metaMenetlusesAvaldused.TypeQualifiedName.Name);
                metaMenetlusesAvaldused.NewSerializer(clazz.MenetlusesAvaldused).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Maarused!=null) {
                Writer.WriteStartElement("maarused");
                global::Xtee.Core.SerializationMetadata metaMaarused = this.GetMetaData(clazz.Maarused);
                Writer.WriteTypeAttribute(metaMaarused.TypeQualifiedName.Namespace, metaMaarused.TypeQualifiedName.Name);
                metaMaarused.NewSerializer(clazz.Maarused).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Registrikaardid!=null) {
                Writer.WriteStartElement("registrikaardid");
                global::Xtee.Core.SerializationMetadata metaRegistrikaardid = this.GetMetaData(clazz.Registrikaardid);
                Writer.WriteTypeAttribute(metaRegistrikaardid.TypeQualifiedName.Namespace, metaRegistrikaardid.TypeQualifiedName.Name);
                metaRegistrikaardid.NewSerializer(clazz.Registrikaardid).WriteXml(Writer);
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmed_v5_ettevotja>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="ettevotja_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>ettevotja_id");
                }
                clazz.EttevotjaId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ettevotja_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmed_v5_ettevotja>ettevotja_id", Reader.LocalName);
            }
            if (Reader.LocalName=="nimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>nimi");
                }
                clazz.Nimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmed_v5_ettevotja>nimi", Reader.LocalName);
            }
            if (Reader.LocalName=="yldandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>yldandmed");
                }
                global::Xtee.Core.SerializationMetadata metaYldandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Yldandmed>(Reader, "detailandmed_v5_yldandmed", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Yldandmed = metaYldandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Yldandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("yldandmed");
                    metaYldandmed.NewSerializer(clazz.Yldandmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="isikuandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>isikuandmed");
                }
                global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Isikuandmed>(Reader, "detailandmed_v5_isikuandmed", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Isikuandmed = metaIsikuandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Isikuandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("isikuandmed");
                    metaIsikuandmed.NewSerializer(clazz.Isikuandmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="kommertspandiandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>kommertspandiandmed");
                }
                global::Xtee.Core.SerializationMetadata metaKommertspandiandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Kommertspandiandmed>(Reader, "detailandmed_v5_kommertspandiandmed", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Kommertspandiandmed = metaKommertspandiandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Kommertspandiandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kommertspandiandmed");
                    metaKommertspandiandmed.NewSerializer(clazz.Kommertspandiandmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="menetluses_avaldused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>menetluses_avaldused");
                }
                global::Xtee.Core.SerializationMetadata metaMenetlusesAvaldused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Dokumendid>(Reader, "detailandmed_v5_dokumendid", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.MenetlusesAvaldused = metaMenetlusesAvaldused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Dokumendid>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("menetluses_avaldused");
                    metaMenetlusesAvaldused.NewSerializer(clazz.MenetlusesAvaldused).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="maarused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>maarused");
                }
                global::Xtee.Core.SerializationMetadata metaMaarused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Maarused>(Reader, "detailandmed_v5_maarused", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Maarused = metaMaarused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Maarused>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("maarused");
                    metaMaarused.NewSerializer(clazz.Maarused).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="registrikaardid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_ettevotja>registrikaardid");
                }
                global::Xtee.Core.SerializationMetadata metaRegistrikaardid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Registrikaardid>(Reader, "detailandmed_v5_registrikaardid", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Registrikaardid = metaRegistrikaardid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Registrikaardid>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("registrikaardid");
                    metaRegistrikaardid.NewSerializer(clazz.Registrikaardid).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
